Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to rewatch removed files in --attach #532

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

phil-opp
Copy link
Collaborator

@phil-opp phil-opp commented Jun 4, 2024

Vim creates a new file inode when modifying files, which results in a 'remove' event. This commit handles this by treating 'remove' events as a trigger for reloads. After sending the reload command, the watcher now tries to watch the same path again, which watches the newly created file.

Fixes #530

@phil-opp
Copy link
Collaborator Author

phil-opp commented Jun 4, 2024

@hbuxiaofei Could you please try whether this PR fixes #530 for you?

Vim creates a new file inode when modifying files, which results in a 'remove' event. This commit handles this by treating 'remove' events as a trigger for reloads. After sending the reload command, the watcher now tries to watch the same path again, which watches the newly created file.
@hbuxiaofei
Copy link

hbuxiaofei commented Jun 6, 2024

@hbuxiaofei Could you please try whether this PR fixes #530 for you?

Yes, this patch does work, but it needs to add the ModifyKind::Metadata and ModifyKind::Name events to work well.

EventKind::Modify(ModifyKind::Metadata(_)) => false,   
EventKind::Modify(ModifyKind::Name(_)) => true,        

Maybe it's because vim creates a temporary .xxx.swp file.

And there are some small problems, some warning logs will appear.

  2024-06-06T07:41:58.048671Z  WARN dora::attach: failed to watch `/home/rayylee/github/code-test/rust/dora-test/python-operator-dataflow/plot.py` again: No such file or directory (os error 2) -> further modifications will be ignored
    at binaries/cli/src/attach.rs:114

@phil-opp
Copy link
Collaborator Author

phil-opp commented Jun 6, 2024

Thanks for testing!

And there are some small problems, some warning logs will appear.

Hmm, this warning indicates that the re-watching failed, so subsequent file changes will be ignored. So this is problematic. Do the warnings still occur after you added the ModifyKind::Metadata and ModifyKind::Name events?

@hbuxiaofei
Copy link

Thanks for testing!

And there are some small problems, some warning logs will appear.

Hmm, this warning indicates that the re-watching failed, so subsequent file changes will be ignored. So this is problematic. Do the warnings still occur after you added the ModifyKind::Metadata and ModifyKind::Name events?

After adding the ModifyKind::Metadata and ModifyKind::Name events, the warning will appear. But hot-reloading works good.

@phil-opp
Copy link
Collaborator Author

phil-opp commented Jun 6, 2024

Could you post the relevant parts of your vim config. I'm trying to reproduce this, but I keep getting normal Modify events.

After adding the ModifyKind::Metadata and ModifyKind::Name events, the warning will appear. But hot-reloading works good.

Adding ModifyKind::Name seems reasonable, but I'm not sure about ModifyKind::Metadata. Ideally, I want to avoid any watch errors if possible. Or alternatively, we could retry a failed watch operation if there is a race between the creation of the new file and the Remove event of the old file.

@hbuxiaofei
Copy link

Could you post the relevant parts of your vim config. I'm trying to reproduce this, but I keep getting normal Modify events.

After adding the ModifyKind::Metadata and ModifyKind::Name events, the warning will appear. But hot-reloading works good.

Adding ModifyKind::Name seems reasonable, but I'm not sure about ModifyKind::Metadata. Ideally, I want to avoid any watch errors if possible. Or alternatively, we could retry a failed watch operation if there is a race between the creation of the new file and the Remove event of the old file.

Here is my vim configuration repository: https://github.com/hbuxiaofei/vimll

But I don't think it has anything to do with the configuration. I cleared my vim configuration and still received this events:

>>> recv events: Event { kind: Modify(Metadata(Any)), paths: ["/home/rayylee/github/code-test/rust/dora-test/python-operator-dataflow/plot.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
>>> recv events: Event { kind: Remove(File), paths: ["/home/rayylee/github/code-test/rust/dora-test/python-operator-dataflow/plot.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }

Vim version :

$ vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Mar 31 2024 00:15:53)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hot reload does not work with complex configuration vim
2 participants